<?php

class PEAR2_REST_Server_Input {

	protected $_message = null;

	public function __construct($input = null) {
		if (is_null($input)) {
			$input = $this->_requestFromStdIn();
		}
		$this->_message = $this->_parseRequest($input);
	}

	protected function _requestFromStdIn() {

		return file_get_contents('php://input');
	}

	protected function _parseRequest($input) {
		return http_parse_message($input);
	}

	public function __get($key) {

		switch($key) {
		case 'httpVersion':
		case 'body':
			return $this->_messages->$key;
			break;
		case 'headers':
			return new PEAR2_HTTP_Request_Headers($this->_message->headers);
			break;
		}
	}

}
